package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Letter;
import cn.wolfcode.trip.base.domain.SystemMessage;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ILetterService;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/letter")
public class LetterController {
    @Autowired
    private ILetterService letterService;



    /**
     * 将某个用户的 所对话聊天的某个人的 所有聊天记录状态设置成 已读
     * @param sendId
     * @param acceptId
     * @param state
     * @return
     */
    @PutMapping
    public JsonResult updateState(Long sendId ,Long acceptId,Integer state){
        JsonResult result = new JsonResult();
        letterService.updateState(sendId,acceptId,state);
        return result;
    }

    /**
     * 根据两个用户ID查询出 他们两个人相关的所有聊天
     * @param sendId
     * @param acceptId
     * @return
     */
    @GetMapping
    public List<Map> get(Long sendId , Long acceptId){
       return letterService.queryBySendIdOrAcceptId(sendId,acceptId);
    }

    /**
     * 发送信息
     * @param sendId
     * @param acceptId
     * @param content
     * @return
     */
    @PostMapping
    public Object sendLetter(Long sendId ,Long acceptId,String content){

        return  letterService.sendLetter(sendId,acceptId,content);
    }
    /**
     * 根据发送者ID 接受者ID查询  未读的信息  并 修改状态
     * @param sendId
     * @param acceptId
     * @return
     */
    @GetMapping("/{acceptId}/{sendId}")
    public List<Map> changeStateAndGetLetters(@PathVariable Long sendId,@PathVariable Long acceptId){
        return letterService.changeStateAndGetLetters(sendId,acceptId);
    }
}
